<template>
	<view>
		<view class="navbar">
			<view style="font-size: 20px;font-weight: 800;color: white;margin-left: 2.5%;">
				<u-icon name="arrow-left" color="#fff" size="24" @click="back"></u-icon>
			</view>
			<view style="font-weight: 100;font-size: 16px;color: #fff;">用户中心</view>
		</view>
		<view>
			<u-cell-group>
				<u-cell title="用户名" :value="userid"></u-cell>
				<!-- <u-cell title="网络监测">
					<view
						slot="value"
					>
						<u-switch v-model="networkFlag" @change="changeNetwork"></u-switch>
					</view>
				</u-cell>
				<u-cell title="当前域" :value="domain"></u-cell>
				<u-cell title="请选择你要使用的域" @click="chooseDomain">
					<u-icon slot="right-icon" size="16" name="arrow-right"  ></u-icon>
				</u-cell> -->
			</u-cell-group>
			<u-picker :show="showDomain" :closeOnClickOverlay="true" @close="showDomain = false" :columns="domainColumns" @cancel="showDomain = false" @confirm="confirm" :defaultIndex="[defaultIndex]"></u-picker>
		</view>
		<u-button type="error" :plain="true" text="退出登录" style="margin-top: 24px;" @click="backLogin"></u-button>
	</view>
</template>


<script>
	export default {
		data() {
			return {
				userid: '',
				networkFlag: false,
				domain: '',
				showDomain: false,
				domainColumns: [],
				defaultIndex: 0
			}
		},
		onLoad: function(option) {
			var _this = this;
			console.log(option);
			// _this.userid = option.userid
			// _this.domain = option.domain
			// _this.domainColumns = []
			// _this.domainColumns.push(JSON.parse(option.domainList))
			// _this.defaultIndex = _this.domainColumns[0].indexOf(_this.domain)
			console.log(_this.domainColumns)
		},
		mounted:function(){
			// if(uni.getStorageSync('network') && uni.getStorageSync('network') ==='open'){
			// 	this.networkFlag = true
			// }else{
			// 	this.networkFlag = false
			// }
		},
		watch: {
		   
		},
		methods:{
			changeNetwork(e){
				console.log(e)
				if(e){
					uni.setStorageSync('network','open')
				}else{
					uni.setStorageSync('network','close')
				}
				const eventChannel = this.getOpenerEventChannel();
				eventChannel.emit('network');
			},
			chooseDomain(){
				this.showDomain = true
			},
			confirm(e){
				console.log(e)
				this.domain = e.value[0]
				this.defaultIndex = this.domainColumns[0].indexOf(this.domain)
				this.$store.dispatch('setDomain',this.domain)
				const eventChannel = this.getOpenerEventChannel();
				console.log(eventChannel)
				eventChannel.emit('acceptDataFromOpenedPage', {data: this.domain});
				console.log(this.$store.getters.getDomain)
				this.showDomain = false
			},
			back(){
				uni.navigateBack()
			},
			backLogin(){
				this.appUtil.logout()
			}
		}
	}
</script>

<style scoped>
	.navbar{
		display: flex;
		align-items: center;
		/* justify-content: space-between; */
		padding:2% 0;
		background-color: #005495;
		width:100%;
	}
</style>